package net.lab1024.sa.user.module.business.course.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.user.module.business.course.dao.TeacherDao;
import net.lab1024.sa.user.module.business.course.domain.entity.TeacherEntity;
import net.lab1024.sa.user.module.business.course.domain.form.TeacherQueryForm;
import net.lab1024.sa.user.module.business.course.domain.vo.TeacherVO;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 教练 Service
 *
 * @Author jabari
 * @Date 2023-08-05 17:08:34
 * @Copyright 51dev.cn
 */

@Service
public class TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<TeacherVO> queryPage(TeacherQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<TeacherVO> list = teacherDao.queryPage(page, queryForm);
        PageResult<TeacherVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    public Map<Integer,TeacherVO> getTeachers(List<Integer> teacher_ids){
        if(teacher_ids.isEmpty()){

            return new HashMap<>();
        }
        List<TeacherEntity> teacherEntityList = teacherDao.selectBatchIds(teacher_ids);
        return teacherEntityList.stream().collect(Collectors.toMap(TeacherEntity::getTeacherId,teacherEntity->{

            TeacherVO teacherVO=new TeacherVO();
            BeanUtils.copyProperties(teacherEntity,teacherVO);
            return teacherVO;

        }));
    }


}
